package com.fengwk.support.util;

import com.fengwk.support.cache.Cache;
import com.fengwk.support.cache.CacheImpl;
import com.fengwk.support.cache.CacheMap;
import com.fengwk.support.cache.CacheMapImpl;
import com.fengwk.support.exception.BaseException;

public class CacheUtils {

	public static final long NO_TIMEOUT = -1L;
	
	private CacheUtils() {
		throw new BaseException("can not instance " + getClass());
	}
	
	/**
	 * 实例化一个缓存对象
	 * 
	 * @param timeout
	 * @return
	 */
	public static <T> Cache<T> cache(long timeout) {
        return new CacheImpl<>(timeout);
    }
	
	/**
	 * 实例化一个缓存对象
	 * 
	 * @param t
	 * @param timeout 毫秒
	 * @return
	 */
	public static <T> Cache<T> cache(T t, long timeout) {
		return new CacheImpl<>(t, timeout);
	}
	
	/**
	 * 实例化一个缓存Map
	 * 
	 * @return
	 */
	public static <K, V> CacheMap<K, V> map() {
		return new CacheMapImpl<>();
	}
	
	/**
	 * 实例化一个缓存Map
	 * 
	 * @param timeout 全局超时,毫秒
	 * @return
	 */
	public static <K, V> CacheMap<K, V> map(long timeout) {
		return new CacheMapImpl<>(timeout);
	}

}
